package com.example.bes.springboot.web.war.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class SessionTest {
    private static final Logger log = LoggerFactory.getLogger(SessionTest.class);
    @GetMapping("/setsession")
    public String setSession(HttpSession session) {
        String id = session.getId();
        log.info("session id: " + id);
        session.setAttribute("useId", "1234567890");
        return id;
    }

    @GetMapping("/getsession")
    public String getSession(HttpSession session) {
        String id = session.getId();
        log.info("session id: " + id);
        Object useId = session.getAttribute("useId");
        log.info("userId: " + useId);
        log.info("userId: " + useId.toString());
        session.setAttribute("useId", "1234567890");
        return id;
    }

}
